<template>
	<view class="content fofa poRel">
		<tabnav :col="back"></tabnav>
		<view style="height: 60rpx;"></view>
		<view class="wid80 mar dis disAl disJuC borRad20 mar-top20 poRel" @click="upImage"
			style="height: 260rpx;border: 1rpx dotted #A8A8A8;">
			<image v-if="!image" src="https://www.sign.run/applet/static/wode/shangchuan.png" style="width: 68rpx;height: 65rpx;"></image>
			<image v-if="image" :src="image" class="borRad10" style="width: 160rpx;height: 220rpx;"></image>
			<uni-icons v-if="image" type="clear" size="30" @click.native.stop="deleteClick" class="poAbs"
				style="top: 10rpx;right: 30rpx;"></uni-icons>
		</view>
		<view class="textCen foSi30" style="margin-top: 42rpx;color: #5E5E5E;">请在白纸上盖章后拍照上传</view>
		<view class="wid100 dis disAl disJuC poAbs" style="height: 140rpx;bottom: 0;">
			<view class="wid80 dis disAl disJuC coFFF hei80 foSi35 borRad10" @click="tijiao"
				:style="'background-color: '+back+';'">确认添加</view>
		</view>
	</view>
</template>

<script>
	import tabnav from "../common/tabnav/tabnav.vue"
	export default {
		components: {
			tabnav,
		},
		data() {
			return {
				back: uni.getStorageSync('back'),
				image: ''
			}
		},
		onLoad() {

		},
		methods: {
			tijiao(){
				if (!this.image) {
					uni.showToast({
						title: '请上传印章',
						icon: 'error'
					})
					return
				}
				uni.navigateBack({
					delta: 1
				})
			},
			tiaozhuan(url){
				uni.redirectTo({
					url: url
				});
			},
			deleteClick() {
				this.image = ''
			},
			upImage(index) {
				var that = this
				uni.chooseImage({
					count: 1, //上传图片的数量，默认是9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						const tempFilePaths = res.tempFilePaths; //拿到选择的图片，是一个数组
						that.image = res.tempFilePaths[0]; //拿到选择的图片，是一个数组
						// that.shangchuan(tempFilePaths,index)
					}
				});
			},
			shangchuan(tempFilePaths, index) {
				var that = this
				uni.uploadFile({
					url: that.global.url + '/api/common/upload',
					header: {
						"token": uni.getStorageSync('token'),
					}, //请求token	
					filePath: tempFilePaths[0],
					name: 'file',
					success: (res) => {
						var apiresult = JSON.parse(res.data)
						if (apiresult.code == 1) {
							console.log(apiresult.data.url);
							that.image = apiresult.data.url
						} else {
							uni.showToast({
								title: apiresult.msg,
								icon: 'error'
							})
						}
					},
					fail() {
						uni.showToast({
							title: "网络连接失败",
							icon: 'error'
						})
					}
				});
			},
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F4F3F3;
	}
	.foSi28{
		font-size: 28rpx;
	}
	.xia{
		height: 1rpx;
		background: #BFBFBF;
	}
</style>
